home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 44 / Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso / -in_the_mag- / basics / blitz / methodbblib.lha / MethodBBLib / Examples / DTPictureExample.asc next >
Text File  |  1997-07-27  |  3KB  |  159 lines

  1. ;Example code for MethodBBLib (C)opyRight 1997 by Erwan Fouret
  2.  
  3. ;##### IMPORTANT #####
  4. ;Include the resident 'blitzlibs:amigalibs.res'
  5. ;in 'Compiler->Compiler Options...'
  6.  
  7.  
  8. ;***** utility/tagitem.h *****
  9. #TAG_USER=(1 LSL 31)
  10.  
  11. ;***** datatypes/datatypesclass.h *****
  12. #DTA_Dummy=(#TAG_USER+$1000)
  13.  
  14. #DTA_LayoutProc=(#DTA_Dummy+27)
  15. #DTA_GroupID=(#DTA_Dummy+31)
  16. #DTA_SourceType=(#DTA_Dummy+101)
  17.  
  18. #DTST_FILE=2
  19.  
  20. ;***** datatypes/datatypes.h *****
  21. #GID_PICTURE=$70696374
  22.  
  23. ;***** datatupes/pictureclass.h ****
  24. NEWTYPE.BitMapHeader
  25.  bmh_Width.w
  26.  bmh_Height.w
  27.  bmh_Left.w
  28.  bmh_Top.w
  29.  bmh_Depth.b
  30.  bmh_Masking.b
  31.  bmh_Compression.b
  32.  bmh_Pad.b
  33.  bmh_Transparent.w
  34.  bmh_XAspect.b
  35.  bmh_YAspect.b
  36.  bmh_PageWidth.w
  37.  bmh_PageHeight.w
  38. End NEWTYPE
  39.  
  40. #PDTA_ModeID=(#DTA_Dummy+200)
  41. #PDTA_BitMapHeader=(#DTA_Dummy+201)
  42. #PDTA_ColorRegisters=(#DTA_Dummy+203)
  43.  
  44.  
  45. ;A little statement to transform bytes greater than 128 into words
  46. Statement adjust{*a.b}
  47.  v.w=Peek.w(*a)
  48.  If v<0
  49.   vv.w=v+256
  50.   Poke.w *a,vv
  51.  EndIf
  52. End Statement
  53.  
  54. DEFTYPE.BitMapHeader *bmhd
  55. DEFTYPE.l *vm
  56.  
  57. Dim *args.b(1)
  58.  
  59. rdargs.l=ReadArgs_("PIC/A",&*args(0),0) ;We read the args
  60.  
  61. If rdargs=0
  62.  PrintFault_ IoErr_(),"ShowDTPic" ;We display an error if no args
  63.  End
  64. EndIf
  65.  
  66. name$=Peek$(*args(0)) ;We get the name from the args
  67.  
  68. Print name$,":"
  69.  
  70. FreeArgs_ rdargs
  71.  
  72. *obj.b=NewDTObjectA_(&name$,VarArgs(#DTA_SourceType,#DTST_FILE,#DTA_GroupID,#GID_PICTURE,0))
  73. ;We create the DT Object
  74.  
  75. If *obj=0
  76.  NPrint "Error creating DT Object !!!"
  77.  End
  78. EndIf
  79.  
  80. GetAttr_ #PDTA_BitMapHeader,*obj,&*bmhd
  81. GetAttr_ #PDTA_ModeID,*obj,&*vm
  82.  
  83. ;We get some informations on the picture
  84. ;And we print them
  85.  
  86. NPrint "(",*bmhd\bmh_Width,"x",*bmhd\bmh_Height,"x",*bmhd\bmh_Depth,")"
  87.  
  88. NPrint "ViewMode = $",Hex$(*vm)
  89.  
  90. w=*bmhd\bmh_Width
  91. h=*bmhd\bmh_Height
  92. d=*bmhd\bmh_Depth
  93.  
  94. If w<320 Then wi=320 Else wi=w
  95.  
  96. Screen 0,*bmhd\bmh_Left,*bmhd\bmh_Top,wi,h,d,*vm,"",1,2
  97.  
  98. *sc.Screen=Peek.l(Addr Screen(0))
  99. ;We get the address of our screen
  100.  
  101. *rp.RastPort=&*sc\_RastPort
  102. ;We get the address of our RastPort
  103.  
  104. ginfo.GadgetInfo\gi_Screen=*sc,0,0,*rp,*rp\Layer
  105. ginfo\gi_Domain\Left=*bmhd\bmh_Left,*bmhd\bmh_Top,w,h
  106. ginfo\gi_Pens\DetailPen=0,0
  107. ginfo\gi_DrInfo=GetScreenDrawInfo_(*sc)
  108.  
  109. ;We create a GadgetInfo structure
  110.  
  111. *gadinfo.GadgetInfo=&ginfo
  112.  
  113. attrs.l=VarArgs(#GA_Left,*bmhd\bmh_Left,#GA_Top,*bmhd\bmh_Top,#GA_Width,w,#GA_Height,h,#ICA_TARGET,#ICTARGET_IDCMP,0)
  114.  
  115. SetDTAttrsA_*obj,0,0,attrs
  116.  
  117. ;We set some attrs to the Object
  118.  
  119. DoMethod *obj,#GM_LAYOUT,*gadinfo,0
  120. ;We draw the Picture on our screen
  121.  
  122. *isdrawn.l=0
  123.  
  124. Repeat                                     ;This loop
  125.  GetAttr_ #DTA_LayoutProc,*obj,&*isdrawn   ;wait for the end
  126. Until *isdrawn=0                           ;of the drawing of the pic
  127.  
  128. AGAPalRGB 0,((2^d)-1),0,0,0 ;init of the palette
  129.  
  130. *creg.b=0
  131.  
  132. GetAttr_ #PDTA_ColorRegisters,*obj,&*creg ;We get the color registers
  133.  
  134. For i=0 To ((2^d)-1)
  135.  r.b=Peek.b(*creg):g.b=Peek.b(*creg+1):b.b=Peek.b(*creg+2)
  136.  rr.w=r:gg.w=g:bb.w=b
  137.  adjust{&rr}:adjust{&gg}:adjust{&bb}
  138.  AGAPalRGB 0,i,rr,gg,bb
  139.  *creg=*creg+3
  140. Next
  141. ;This routine create the palette
  142.  
  143. ShowPalette 0
  144.  
  145. DoMethod *obj,#GM_RENDER,*gadinfo,*rp,1 ;We refresh the pic
  146.  
  147. Repeat
  148. Until Joyb(0)=2
  149.  
  150. ;We quit the prog
  151.  
  152. Free Palette 0
  153.  
  154. Free Screen 0
  155.  
  156. DisposeDTObject_ *obj
  157.  
  158. End
  159.